package com.ewanghuiju.app.ui.shopmail.adapter;

import android.graphics.Paint;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.component.ImageLoader;
import com.ewanghuiju.app.model.bean.local.LimitedSeckillMainBean;
import com.ewanghuiju.app.util.StringUtil;
import com.makeramen.roundedimageview.RoundedImageView;

/**
 * @author sj  qq:751943509
 * @class 限时秒杀 内容部分
 * @time 2020/2/20
 */
public class LimitedSeckillMainAdapter extends BaseQuickAdapter<LimitedSeckillMainBean, BaseViewHolder> {
    private int mType;

    @Override
    public long getItemId(int position) {
        return position;
    }

    public LimitedSeckillMainAdapter(int layoutResId, int mType) {
        super(layoutResId);
        this.mType = mType;
    }

    @Override
    protected void convert(BaseViewHolder helper, LimitedSeckillMainBean item) {
        TextView tv_title = helper.getView(R.id.tv_shop_title);
        TextView tv_yuan = helper.getView(R.id.tv_yuan_price);
        TextView tv_qg_num = helper.getView(R.id.tv_qg_num);
        if (mType == Constants.LIMITEDSECKILL_TYPE_YHQ) {
            StringUtil.getTextStrFormat(tv_title, "AA", item.getTitle());
            tv_qg_num.setText(item.getCanbuynum());
            helper.setText(R.id.tv_spe_price, item.getSpejia());
            tv_yuan.setText("￥" + item.getYuanjia());
            helper.setText(R.id.tv_yhq, item.getYhq() + "元券");
            helper.setText(R.id.tv_ygz, "预估赚 ￥" + item.getYgz());
            helper.setText(R.id.tv_sjz, "升级赚 ￥" + item.getSjz());
            ImageView iv_lab = helper.getView(R.id.iv_lab);
            ImageLoader.load(mContext, item.getStatus() == 0 ? R.mipmap.icon_taobao_small : R.mipmap.icon_tianmao_small, iv_lab);
        } else {
            tv_yuan.setText("1999");
            tv_title.setText(item.getTitle());
            helper.setText(R.id.tv_spe_price, "1000");
            tv_qg_num.setText("仅限100件");
        }
        tv_yuan.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); // 设置中划线并加清晰
        RoundedImageView riv = helper.getView(R.id.riv_item_icon);
        ImageLoader.load(mContext, item.getImg(), riv);
        ProgressBar progressBar = helper.getView(R.id.xsqg_progressbar);
        TextView tv_pg = helper.getView(R.id.text_progressbar);
        if (item.getStatus() == 1) {
            helper.setVisible(R.id.layout_progressbar, true);
            tv_qg_num.setVisibility(View.VISIBLE);
            helper.setVisible(R.id.layout_kq, false);
            if (item.getPg() >= 100) {
                progressBar.setProgressDrawable(mContext.getResources().getDrawable(R.drawable.main_pb_finish_bg));
            } else {
                progressBar.setProgressDrawable(mContext.getResources().getDrawable(R.drawable.main_pb_bg));
            }
            progressBar.setProgress(item.getPg());
            tv_pg.setText(item.getPg() + "%");
        } else {
            helper.setVisible(R.id.layout_progressbar, false);
            tv_qg_num.setVisibility(View.INVISIBLE);
            helper.setVisible(R.id.layout_kq, true);
            helper.setText(R.id.tv_kq_time, "10:00");
        }
    }
}
